//
//  DateFormatterUtility.swift
//  NyamanDana
//
//  Created by 李永彬 on 2025/10/22.
//

import UIKit

final class DateFormatterUtility {
    static let shared = DateFormatterUtility()
    
    private let dateFormatter: DateFormatter
    
    private init() {
        dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd/MM/yyyy"
        dateFormatter.locale = Locale(identifier: "en_US_POSIX")
        dateFormatter.timeZone = TimeZone.current
    }
    
    func date(from string: String) -> Date? {
        return dateFormatter.date(from: string)
    }
    
    func string(from date: Date) -> String {
        return dateFormatter.string(from: date)
    }
    
    func isValidDateString(_ dateString: String) -> Bool {
        return date(from: dateString) != nil
    }
}
